{include file='admin/header.html'}

<form class="layui-form" style="margin-top: 15px;">
    <!-- 表单字段 -->
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.username}</label>
        <div class="layui-input-inline">
            <input type="text" name="username" value="{$row.username}" disabled="disabled"
                placeholder="{$tran.input_username}" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">{$tran.cannot_modify}</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.password}</label>
        <div class="layui-input-inline">
            <input type="password" name="password" value="" placeholder="{$tran.empty_not_change}" autocomplete="off"
                class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.nickname}</label>
        <div class="layui-input-inline">
            <input type="text" name="nickname" value="{$row.nickname}" placeholder="" autocomplete="off"
                class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.phone}</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" value="{$row.phone}" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.avatar}</label>
        <div class="layui-input-inline">
            <input type="text" name="avatar" id="upload-avatar" value="{$row.avatar}" autocomplete="off"
                class="layui-input">
        </div>
        <div class="layui-word-aux"><button type="button" class="layui-btn layui-btn-primary"
                id="upload-btn">{$tran.upload}</button></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="id" value="{$row.id}">
            <button class="layui-btn" lay-submit lay-filter="profile">{$tran.save}</button>
            <button type="reset" class="layui-btn layui-btn-primary">{$tran.reset}</button>
        </div>
    </div>
</form>

<script>
    // JS
    layui.use(['form', 'upload'], function () {
        var form = layui.form,
            upload = layui.upload,
            $ = layui.jquery;

        var site_url = '//{$smarty.server.SERVER_NAME}' + (('{$smarty.server.SERVER_PORT}' == '80' || '{$smarty.server.SERVER_PORT}' == '443') ? '' : ':{$smarty.server.SERVER_PORT}');

        // 上传
        upload.render({
            elem: '#upload-btn',
            url: site_url + '/{$lang}/admin/media/upload.html',
            data: {},
            done: function (res, index, upload) {
                if (res.code > 0) return layer.msg('{$tran.upload_fail}', { icon: 2 });
                $('#upload-avatar').val(res.data.src)
            },
        });

        // 监听提交
        form.on("submit(profile)", function (data) {
            $.post(site_url + '/{$lang}/admin/profile.html', data.field, function (res) {
                if (res.code) {
                    return layer.alert(res.msg, { title: '{$tran.info}', icon: 2 });
                }
                layer.alert(res.msg, { title: '{$tran.info}', icon: 1 }, function (index) {
                    layer.close(index);
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }, "json");
            return false;
        });
    });
</script>

{include file='admin/footer.html'}